<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="90px">
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          class="filter-item"
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
      </el-form-item>
    </el-form>
    
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
            <el-button
                type="success"
                icon="el-icon-user"
                size="mini"
                :disabled="single"
                @click="handleOption(2)"
                v-hasPermi="['business:tixian:check']"
            >审核</el-button>
      </el-col>
      <el-col :span="1.5">
            <el-button
                type="danger"
                icon="el-icon-delete"
                size="mini"
                :disabled="single"
                @click="handleOption(-1)"
                v-hasPermi="['business:tixian:remove']"
            >作废</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="单号" align="center" prop="payNo" />
        <el-table-column label="积分数量" align="center" prop="payAccumulate" />
        <el-table-column label="金额" align="center" prop="payMoney" />
        <!-- <el-table-column label="积分来源" align="center">
            <template slot-scope="scope">
                <span v-html="getType(scope.row.payType)"></span>
            </template>
        </el-table-column> -->
        <el-table-column label="状态" align="center">
            <template slot-scope="scope">
                <span v-html="getOrderType(scope.row.status)"></span>
            </template>
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getListFn"
    />
    
    <el-dialog title="审核" :visible.sync="isShowCheck" width="800px" append-to-body @click="cancelCheck">
        <el-form ref="dcForm">
          <el-form-item label="图片上传:">
                    <el-upload accept=""
                            multiple
                            :limit="1"
                            action="#"
                            list-type="picture-card"
                            :file-list="fileList"
                            :on-change="handleChange"
                            :http-request="uploadFile">
                            <i class="el-icon-upload el-icon--right"></i>
                    </el-upload>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="handleChcked">确 定</el-button>
                <el-button @click="cancelCheck">取 消</el-button>
            </div>
    </el-dialog>
    <el-dialog title="作废" :visible.sync="isShowdel" width="400px" append-to-body @click="cancelDel">
            <el-form>
                <el-form-item label="备注:">
                    <el-input
                        type="textarea"
                        :rows="2"
                        placeholder="请输入内容"
                        v-model="desc">
                    </el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="handleDel">确 定</el-button>
                <el-button @click="cancelDel">取 消</el-button>
            </div>
    </el-dialog>
  </div>
</template>

<script>
import { axios_getList, axios_check, axios_cancel } from "@/api/system/withdrawal";
import { getCustomCityList } from "@/api/system/customer";
import { getToken } from '@/utils/auth';
import axios from 'axios';

export default {
  name: "withdrawal",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 公司信息表格数据
      infoList: [],
      // 日期范围
      dateRange: [],
      search: '',
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        accumulateType: undefined,
        orderNum: undefined,
        areaCode: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: undefined,
      },
      // 表单参数
      form: {
        provinceObj: undefined,
        cityObj: undefined,
      },
        // 表单校验
        rules: {},
        provinceList: [],
        cityList: [],
        isShowRecharge: false,
        accumulatePoint: null,

        formFileList: null,
        isShowCheck: false,
        fileList: [],
        desc: '',
        isShowdel: false
    };
  },
  created() {
    this.getListFn();
  },
  methods: {
    //  积分来源类型
    getType(type){
        // 0:充值 1:订单消费 2:分享码 3:提现 4:人工充值
        switch(type){
            case 0:
                return '微信赎回';
            break;
            case 1:
                return '支付宝赎回';
            break;
            case 2:
                return '银行卡赎回';
            break;
        }
    },
    
    getOrderType(type) {
        switch (type) {
            case -1:
                return '作废';
                break;
            case 0:
                return '新增';
                break;
            case 1:
                return '提现成功';
                break;
            default:
                return '新增';
        }
    },
    
    /** 查询公司信息列表 */
    getListFn() {
        this.loading = true;
        if(this.dateRange === null){
            this.dateRange = ['',''];
        }
        this.queryParams.begTime = this.dateRange[0];
        this.queryParams.endTime = this.dateRange[1];
        axios_getList(this.queryParams).then(response => {
                this.infoList = response.rows;
                this.total = response.total;
                this.loading = false;
        });
    },
    getAreaListFn(type,id,isEdit){
        if(isEdit !== 'edit'){
            this.form.cityObj = undefined;
        }
        exportCityList({leveType: type,parentId: id}).then(res => {
            if(res.code === 'success'){
                for(let i = 0; i< res.data.length; i++){
                    delete res.data[i].parent_id;
                }
                if(type === 1){
                    this.provinceList = res.data;
                }else if(type === 2){
                    this.cityList = res.data;
                }
            }
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cId: undefined,
        cName: undefined,
        orderNum: undefined,
        areaCode: undefined,
        leader: undefined,
        phone: undefined,
        email: undefined,
        status: "0",
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        provinceObj: undefined,
        cityObj: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getListFn();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length;
    },
    
    
        // 审核，作废
        handleOption(status){
            if(status === 2){
                this.cancelCheck();
                return;
            }else{
                this.isShowdel = true;
            }
        },

        // 取消删除
        cancelDel(){
            this.isShowdel = !this.isShowdel;
        },

        // 确定删除
        handleDel(){
            let params = {
                id: this.ids[0],
                desc: this.desc
            }
            let that = this;
            axios_cancel(params).then(res =>{
                if(res.code === 'success'){
                    that.msgSuccess("操作成功!");
                    that.getListFn();
                    that.cancelDel();
                }else{
                    that.msgError("操作失败!");
                }
            })
        },
        
        // 
        uploadFile(param){
            let fileObj = param.file;
            // 文件对象
            this.formFileList = fileObj;
        },
        
        //监控上传文件列表
        handleChange (file, fileList) {
            // let existFile = fileList.slice(0, fileList.length - 1).find(f => f.name === file.name);
            // if (existFile) {
            //     this.$message.error('当前文件已经存在!');
            //     fileList.pop();
            // }
            // this.fileList = fileList;
        },

        // 审核
        handleChcked(){
            let that = this;
            let formData = new FormData();
            formData.append("file", this.formFileList);
            
            axios.defaults.headers['Content-Type'] = 'multipart/form-data'
            axios.defaults.headers['Authorization'] = 'Bearer ' + getToken()
            let url = process.env.VUE_APP_BASE_API + '/system/payBackInfoController/checkPayBackInfo?id='+this.ids[0];
            console.log(process.env.VUE_APP_BASE_API,456)
            axios.post(url, formData)
            .then(function (response) {
                that.msgSuccess("操作成功!");
                that.cancelCheck();
                that.getListFn();
            })
            .catch(function (error) {
                console.log(error);
            });
        },
        
        // 关闭审核弹框
        cancelCheck(){
            this.fileList = [];
            this.isShowCheck = !this.isShowCheck;
        },
    
  }
};
</script>